/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author James
 */
@Entity
public class ItemCategory implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long    id;
    private String  name;
    private String  description;
    private int     discount;     // percentage will be negative (e.g. -20 will be 20% discount), amount will be positive (e.g. 20 will be $20 discount)
    private long    createdDate;
    private boolean active;
    private boolean deleted;
    @ManyToOne
    private Partner thePartner;
    @ManyToOne
    private Outlet theOutlet;
    @OneToMany(cascade={CascadeType.ALL}, mappedBy="theCategory")
    private List<Item> listOfItems;
    
    public ItemCategory() {
        this.discount    = 0;
        this.active      = false;
        this.deleted     = false;
        this.createdDate = System.currentTimeMillis();
        this.listOfItems = new ArrayList<Item>();
    }
    
    public void createItemCategory(String name, String description, Partner thePartner, Outlet theOutlet) {
        this.name        = name;
        this.description = description;
        this.thePartner  = thePartner;
        this.theOutlet   = theOutlet;
    }
    
    public void addItem(Item theItem) {
        this.listOfItems.add(theItem);
    }
    
    //Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(long createdDate) {
        this.createdDate = createdDate;
    }

    public Outlet getOutlet() {
        return theOutlet;
    }

    public void setOutlet(Outlet theOutlet) {
        this.theOutlet = theOutlet;
    }

    public Partner getPartner() {
        return thePartner;
    }

    public void setPartner(Partner thePartner) {
        this.thePartner = thePartner;
    }

    public List<Item> getListOfItems() {
        return listOfItems;
    }

    public void setListOfItems(List<Item> listOfItems) {
        this.listOfItems = listOfItems;
    }

    public int getDiscount() {
        return discount;
    }

    public void setDiscount(int discount) {
        this.discount = discount;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemCategory)) {
            return false;
        }
        ItemCategory other = (ItemCategory) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.ItemCategory[ id=" + id + " ]";
    }
    
}
